package Client.GUI;

import java.util.ArrayList;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import Server.DataBase.Parent;

public class ParentTableModel extends AbstractTableModel {

	  /**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		Vector<String[]> cache; // will hold String[] objects . . .

		int colCount=3;

		String[] headers = {"ID", "Last Name", "First Name"};

		public ParentTableModel() {
			cache = new Vector<String[]>();
		}

		public String getColumnName(int i) {
			return headers[i];
		}

		public int getColumnCount() {
			return colCount;
		}

		public int getRowCount() {
			return cache.size();
		}

		public Object getValueAt(int row, int col) {
			return ((String[]) cache.elementAt(row))[col];
		}
	  
		public void setValueAt(int row, int col, String msg){
		  ((String[]) cache.elementAt(row))[col] = msg;
		  fireTableChanged(null);
	  }
	  
	  public void setArray(ArrayList<Parent> array){
		  cache.removeAllElements();
		  for (int i=0; i<array.size(); i++) addToArray(array.get(i));
		  fireTableChanged(null);
	  }
	  
	  public void addToArray(Parent parent){
		  String[] record = new String[colCount];
		  record[0] = Integer.toString(parent.getIdUser());
		  record[1] = parent.getLastName();
		  record[2] = parent.getFirstName();
		  cache.addElement(record);
	  }
	}